package com.s2u2m.training.ex_programmer.open_closed.bad;

/**
 * 当添加新形状时，需要修改getSum方法
 */
public class SumCalculator {

    public Long getSum(Object obj) {
        if (obj instanceof Rectangle) {
            Rectangle rectangle = (Rectangle) obj;
            return rectangle.getLength() * rectangle.getWidth();
        }

        if (obj instanceof Square) {
            Square square = (Square) obj;
            return square.getLength() * square.getLength();
        }

        throw new RuntimeException("Invalid Param");
    }
}
